<template>
	<view class="" style="height: 100%; width: 100%;">
		<MyTopScrollView topHeight="61px" >
			<view slot="top" style="height: 100%;" class="bk-white-gray pd-h-xl lay-c-c">
				<view class="flex1">
					<view class="text-lg">{{day}}</view>
					<view class="gray mg-t-sm">{{"收入"+income+"， 支出"+expenditure}}</view>
				</view>
				<picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
					<view class="uni-input"><image class="logo" src="https://mer.chuidiaotop.com/static/images/ri_li.png"></image></view>
				</picker>
				
			</view>
			<view slot="body">
				<view v-for="(item, index) in bills" :key="index" class="pd-xl solid-bottom line-white-gray lay-c-c">
					<view class="flex1">
						<view class="text-lg text-bold">{{item.name}}</view>
						<view class="gray mg-t-sm">{{item.time}}</view>
					</view>
					<view class="text-lg">{{item.money}}</view>
				</view>
			</view>
		</MyTopScrollView>
		
		<picker-view v-if="date_picker_visible" :indicator-style="indicatorStyle" :mask-style="maskStyle" :value="value" @change="bindChange">
			<picker-view-column>
				<view class="item" v-for="(item,index) in years" :key="index">{{item}}年</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" v-for="(item,index) in months" :key="index">{{item}}月</view>
			</picker-view-column>
			<picker-view-column>
				<view class="item" v-for="(item,index) in days" :key="index">{{item}}日</view>
			</picker-view-column>
		</picker-view>
	</view>
</template>

<script>
	import {
	  getMerBills
	} from "@/api/fsh.js";
	
	import MyTopScrollView from '../components/my/MyTopScrollView.vue';
	export default {
		components: {
			MyTopScrollView
		},
		data() {			
			return {
				day: '',
				income: '',
				expenditure: '',
				bills: [
				],
				today: new Date().format("yyyy-MM-dd"),
				startDate: '2022-01-01',
				endDate: '2023-01-01',
			}
		},
		onLoad(options) {
			this.merId = options.merId;
			this.getMerBills(new Date().format('yyyy-MM-dd'));
		},
		methods: {
			getMerBills: function(day) {
				getMerBills(this.merId, day).then(res=>{
					this.day = res.entity.day;
					this.income = res.entity.income;
					this.expenditure = res.entity.expenditure;
					this.bills = res.entity.bills;
				}).catch(err=>{
					console.error("getMerBills fail:", err)
				})
			},
			
			bindDateChange: function(e) {
				this.getMerBills(e.detail.value);
			}
		}
	}
</script>

<style lang="scss">
	@import "@/leui.scss";
	
	page {
		height: 100vh;
		width: 100%;
	}
</style>
